(async ()=>{
    const Sequelize = require('sequelize')

    //建立连接
    const sequelize = new Sequelize('kaikeba','root','asd13579',{
        host:'localhost',
        dialect:'mysql'
    })

    //定义模型
    const Fruit = sequelize.define('Fruit',{
        id:{
            type:Sequelize.DataTypes.UUID,
            defaultValue:Sequelize.DataTypes.UUIDV1,
            primaryKey:true
        },
        name:{type:Sequelize.STRING(20),allowNull:false},
        price:{type:Sequelize.FLOAT,allowNull:false},
        stock:{type:Sequelize.INTEGER,defaultValue:0}
    },{
        // timestamps:false //不生成插入时间和更新时间
        // tableName:'TBL_FRUIT'//指定表名
    })

    //同步数据库，force：true则会删除已存在的表
    let ret = await Fruit.sync({force:false})
    console.log('sync',ret)

    ret = await Fruit.create({
        name:"香蕉",
        price:3.6
    })
    console.log('create',ret)

    ret = await Fruit.findAll()
    await Fruit.update(
        {price:4.2},
        {where:{name:'香蕉'}}
        )
    console.log('findAll',JSON.stringify(ret))

    const Op = Sequelize.Op;
    ret = await Fruit.findAll({
        where:{price:{[Op.lt]:4,[Op.gt]:2}}
    })
    console.log('findAll',JSON.stringify(ret,'','\t'))

})()